﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.XR.ARFoundation;

/// <summary>
/// 设置图片跟踪是否可用
/// </summary>
public class ImageTrackingManager : MonoBehaviour
{
    private ARTrackedImageManager mARTrackedImageManager;

    private void Awake()
    {
        mARTrackedImageManager = FindObjectOfType<ARTrackedImageManager>();
    }

    // Start is called before the first frame update
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
        
    }

    /// <summary>
    /// 切换图片跟踪是否可用
    /// </summary>
    public void ToggleImageTrackingEnabled()
    {
        mARTrackedImageManager.enabled = !mARTrackedImageManager.enabled;

        string trackingImageMessage = "";
        if (!mARTrackedImageManager.enabled)
        {
            trackingImageMessage = "设置了图片跟踪 不可用";
            SetAllImagesActive(false);
        }
        else
        {
            trackingImageMessage = "设置了图片跟踪 可用";
            SetAllImagesActive(true);
        }

        ToastUtil.showToast("planeDetectionMessage = " + trackingImageMessage);
    }

    private void SetAllImagesActive(bool value)
    {
        foreach (var img in mARTrackedImageManager.trackables)
            img.gameObject.SetActive(value);
    }
}
